package com.paperless.util;

import com.mogujie.tt.protobuf.InterfaceMacro;
import com.mogujie.tt.protobuf.InterfaceMember;

import java.util.List;

/**
 * @author : Administrator
 * @date : 2023/4/17 15:50
 * @description :
 */
public class SDKUtil {
    /**
     * 判断value是否包含指定的constant
     * <p>e.g: flag, InterfaceMacro.Pb_TableCardFlag.Pb_MEET_TABLECARDFLAG_SHOW_VALUE</p>
     *
     * @param value    值
     * @param constant 一个固定的值
     */
    public static boolean contains(int value, int constant) {
        return (value & constant) == constant;
    }

    public static boolean isCardShow(int flag) {
        return contains(flag, InterfaceMacro.Pb_TableCardFlag.Pb_MEET_TABLECARDFLAG_SHOW_VALUE);
    }

    public static boolean isCardBold(int flag) {
        return contains(flag, InterfaceMacro.Pb_TableCardFlag.Pb_MEET_TABLECARDFLAG_BOLD_VALUE);
    }

    /**
     * @param items 参会人 {@link InterfaceMember.pbui_Item_MemberDetailInfo}
     * @return <json>
     * {
     * "member": [{
     * "name": "陈工 ",
     * "company": "xx",
     * "job": "xx",
     * "phone": "123456",
     * "email": "",
     * "comment": "",
     * "password": "123456",
     * "memid": "",
     * "devid": "",
     * "perm": "",
     * "role": ""
     * }]
     * }
     * </json>
     */
    public static String parseFrom(List<InterfaceMember.pbui_Item_MemberDetailInfo> items) {
        StringBuilder sb = new StringBuilder();
        sb.append("{\"member\":[");
        for (int i = 0; i < items.size(); i++) {
            InterfaceMember.pbui_Item_MemberDetailInfo item = items.get(i);
            if (i != 0) {
                sb.append(",");
            }
            sb.append("{\"name\":\"").append(item.getName().toStringUtf8()).append("\",");
            sb.append("\"company\":\"").append(item.getCompany().toStringUtf8()).append("\",");
            sb.append("\"job\":\"").append(item.getJob().toStringUtf8()).append("\",");
            sb.append("\"phone\":\"").append(item.getPhone().toStringUtf8()).append("\",");
            sb.append("\"email\":\"").append(item.getEmail().toStringUtf8()).append("\",");
            sb.append("\"comment\":\"").append(item.getComment().toStringUtf8()).append("\",");
            sb.append("\"password\":\"").append(item.getPassword().toStringUtf8()).append("\"}");
        }
        sb.append("]}");
        return sb.toString();
    }
}
